'use strict';
const dayjs = require("dayjs");
module.exports = app => {
  const { INTEGER, DATE, STRING } = app.Sequelize;
  const Dept = app.model.define(
    'Dept',
    {
      id: {type: INTEGER, primaryKey: true, autoIncrement: true},
      pid: INTEGER,
      name: STRING,
      code: STRING,
        nickname: STRING,
        phone: STRING,
      create_time: {
        type: DATE,
        get() {
          return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
        }
      },
      updated_time: {
        type: DATE,
        get() {
          return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
        }
      }
    },
    {
      tableName: 'dept',
      timestamps: true, // 启用时间戳(createdAt, updatedAt)
      updatedAt: 'updated_time', // 不想要 updatedAt
      createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 create_time
    }
  );
  return Dept;
};
// 创建mysql建表语句
// CREATE TABLE `dept` (
//   `id` int(11) NOT NULL AUTO_INCREMENT,
//   `code` varchar(255) DEFAULT NULL,
//   `name` varchar(255) DEFAULT NULL,
//   `create_time` datetime DEFAULT NULL,
//   `updated_time` datetime DEFAULT NULL,
//   PRIMARY KEY (`id`)
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

